package middlewares

import (
	"github.com/gin-gonic/gin"
)

type RequestHelper struct {
}

type UserSessionLoginInfo struct {
	TenantID int    `json:"tenantId"`
	Token    string `json:"token"`
	//LoginType string `json:"loginType"`
	UserID    int    `json:"userId"`
	LoginName string `json:"loginName"`
	UserName  string `json:"userName"`
}

func GetUserToken(c *gin.Context) *UserSessionLoginInfo {
	var token = c.Request.Header.Get("token")
	if token == "" {
		var cook, _ = c.Request.Cookie("token")
		if cook != nil {
			token = cook.Value
		}
	}
	if token == "" {
		return nil
	}
	var info = NewUserTokenCache().GetTokenInfo(token)

	return info
}
func GetUserIdByToken(c *gin.Context) int {
	token := GetUserToken(c)
	if token == nil {
		return 0
	}
	return token.UserID
}
